<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

/* @codingStandardsIgnoreFile*/

?>
<?php
/**
 * @description:
 *
 */
?>
<?php
    $_helper = $this->helper('Mazentop\AdvancedReview\Helper\Data');
    // $_items = $block->getReviewsCollection()->getItems();
    $Reviews_Page_Limit = 20;
    $reviewListToolbarBlock = $block->getChildBlock('toolbar');
    $requested_page = $reviewListToolbarBlock->getRequest()->getParam($reviewListToolbarBlock->getPageVarName(), 1);
    $reviewListToolbarBlock->setAvailableLimit([$Reviews_Page_Limit => $Reviews_Page_Limit]);
    $reviewListToolbarBlock->setShowPerPage(false)->setShowAmounts(false)->setLimit($Reviews_Page_Limit)->setCollection($block->getReviewsCollection()->clear());
    $_collection = $reviewListToolbarBlock->getCollection()->setCurPage($requested_page)->load()->addRateVotes();
    $_items = $_collection->getItems();

    $format = $block->getDateFormat() ?: \IntlDateFormatter::SHORT;

    $imgHelper = $this->helper('Mazentop\AdvancedReview\Helper\Image');
?>

<?php if (count($_items)):?>
<div class="block review-list ad-review" id="customer-reviews">
    <div class="block-title">
        <strong><?php /* @escapeNotVerified */ echo __('Customer Reviews') ?></strong>
    </div>
    <div class="block-content">
        <div class="toolbar review-toolbar">
            <?php echo $block->getChildHtml('toolbar') ?>
        </div>
        <ol class="items review-items">
        <?php foreach ($_items as $_review):?>
            <li class="item review-item" itemscope itemprop="review" itemtype="http://schema.org/Review">
                <div class="review-title" itemprop="name"><?php echo $block->escapeHtml($_review->getTitle()) ?></div>
                <?php if (count($_review->getRatingVotes())): ?>
                    <div class="review-ratings">
                    <?php foreach ($_review->getRatingVotes() as $_vote): ?>
                    <div class="rating-summary item" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
                        <span class="label rating-label"><span><?php echo $block->escapeHtml($_vote->getRatingCode()) ?></span></span>
                        <div class="rating-result" title="<?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%">
	                        <meta itemprop="worstRating" content = "1"/>
	                        <meta itemprop="bestRating" content = "100"/>
                            <span style="width:<?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%">
                                <span itemprop="ratingValue"><?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%</span>
                            </span>
                        </div>
                    </div>
                    <?php endforeach; ?>
                    </div>
                <?php endif; ?>
                <div class="review-content" itemprop="description">
                    <?php echo nl2br($block->escapeHtml($_review->getDetail())) ?>
                    <?php $baseurl  = $this->getUrl(); ?>
                    <?php if($_review->getData('advanced_img')): ?>
                    <?php $review_image = $_helper->getReviewImages($_review->getData('advanced_img')); ?>
                    <div class="re_image">
                    <?php foreach($review_image as $v) :
                           $img = $imgHelper->resize($v['img']);
                     ?>
                        <img src="<?php echo $img;?>"/>
                    <?php endforeach; ?>
                    </div>
                    <?php endif; ?>
                    <?php 
                        if($_review->getData('advanced_video')&&($videohtml = $_helper->getVideo($_review->getData('advanced_video')))){
                            echo '<div class="re_video"><div class="clickdiv"></div>';
                            echo $videohtml;
                            echo '</div>';
                        }
                    ?>
                </div>
                <div class="review-details">
                    <p class="review-author">
                        <span class="review-details-label"><?php /* @escapeNotVerified */ echo __('Review by')?></span>
                        <strong class="review-details-value" itemprop="author"><?php echo $block->escapeHtml($_review->getNickname()) ?></strong>
                    </p>
                    <p class="review-date">
                        <span class="review-details-label"><?php /* @escapeNotVerified */ echo __('Posted on') ?></span>
                        <time class="review-details-value" itemprop="datePublished" datetime="<?php /* @escapeNotVerified */ echo $block->formatDate($_review->getCreatedAt(), $format) ?>"><?php /* @escapeNotVerified */ echo $block->formatDate($_review->getCreatedAt(), $format) ?></time>
                    </p>
                </div>
            </li>
        <?php endforeach; ?>
        </ol>
        <div class="toolbar review-toolbar">
            <?php echo $block->getChildHtml('toolbar') ?>
        </div>
    </div>
</div>
<?php endif;?>
